#!/bin/sh

passwd_bytes=

if [ "$#" -eq 1 ]; then
	passwd_bytes=$(od -An -tx1 -N9 "$1")
elif [ "$#" -gt 1 ]; then
	passwd_bytes="$*"
else
	passwd_bytes=$(cat | od -An -tx1 -N9)
fi

unmask_passwd() {
	local mask_bytes="$*"
	local unmasked=
	local masked_byte=

	for byte in $passwd_bytes; do
		masked_byte=$(printf "%02x" `echo $((0x$byte ^ 0x$1))`)
		unmasked="${unmasked} ${masked_byte}"
		shift
		if [ "$#" -eq 0 ]; then
			set -- $mask_bytes
		fi
	done

	echo $unmasked
}

if [ -z "$mask_bytes" ]; then
	mask_bytes='64 f4 90 51 2c 67 5d 8f 6d'
fi

passwd_unmasked=$(unmask_passwd $mask_bytes)

echo $passwd_unmasked
